%计算L1误差
function L1_error = compute_l1(a_coef,tri,b_value,t)
%coef = [1/3;1/3;1/3];
coef = [0.1259391805448;0.1259391805448;0.1259391805448;
    0.1323941527885;0.1323941527885;0.1323941527885;0.225];
N = size(a_coef,1);
errors = 0;
for i = 1 : N
    num_value = a_coef(i,:)*b_value;
    new_nodes = real_and_ref(tri(i).nodes);
    n = size(new_nodes,1);
    true_value = zeros(1,n);
    for j = 1 : size(new_nodes,1)
        x = new_nodes(j,1);
        y = new_nodes(j,2);
        true_value(j) = sin(2*pi*(x + y - 2*t));
    end
    value = abs(true_value - num_value);
    errors = errors + value*coef*tri(i).area;
end
L1_error = errors;
end

function [new_nodes, det_jaco] = real_and_ref(nodes)
gauss_points = [0.1012865073235, 0.1012865073253;
                0.7974269853531, 0.1012865073253;
                0.1012865073235, 0.7974269853531;
                0.4701420641051, 0.0597158717898;
                0.4701420641051, 0.4701420641051;
                0.0597158717898, 0.4701420641051;
                0.3333333333333, 0.3333333333333];
new_nodes = zeros(size(gauss_points));
Jacobi = [-nodes(1,1)+nodes(2,1), nodes(3,1) - nodes(1,1);
    -nodes(1,2)+nodes(2,2), nodes(3,2) - nodes(1,2)];
det_jaco = abs(det(Jacobi));
for i = 1:size(gauss_points,1)
    xi = gauss_points(i,1);
    eta = gauss_points(i,2);
    
    % 计算形函数
    N1 = 1-xi-eta;
    N2 = xi;
    N3 = eta;
    
    % 计算实际坐标 (x,y)
    x = N1*nodes(1,1) + N2*nodes(2,1) + N3*nodes(3,1);
    y = N1*nodes(1,2) + N2*nodes(2,2) + N3*nodes(3,2);
    new_nodes(i,:) = [x, y];
end
end